package com.mb.app.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.mb.app.domain.TbChannelConfig;
import com.mb.app.dao.TbChannelConfigMapper;
import com.mb.app.service.ITbChannelConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 渠道配置信息  服务实现类
 * </p>
 *
 * @author liliping
 * @since 2019-03-21
 */
@Service
@Slf4j
public class TbChannelConfigServiceImpl extends ServiceImpl<TbChannelConfigMapper, TbChannelConfig> implements ITbChannelConfigService {


    @Override
    public List<TbChannelConfig> queryList(Map<String, Object> map) {
        List<TbChannelConfig> list = this.baseMapper.lst(map);
        return list;
    }

    @Override
    public int count(Map<String, Object> map) {
        return this.baseMapper.countt(map);
    }

    @Override
    public int save(TbChannelConfig TbChannelConfig) {
        TbChannelConfig.setCreateTime(new Date());
        return this.baseMapper.insert(TbChannelConfig);
    }

    @Override
    public int update(TbChannelConfig TbChannelConfig) {
        try {
            TbChannelConfig TbChannelConfig1 = new TbChannelConfig();
            TbChannelConfig1.setChannelId(TbChannelConfig.getChannelId());
            TbChannelConfig1.setDataStatus(1);
            TbChannelConfig TbChannelConfigDO = this.baseMapper.selectOne(TbChannelConfig1);
            if(TbChannelConfigDO != null){
                TbChannelConfig.setUpdateTime(new Date());
                this.baseMapper.updateById(TbChannelConfig);
            }
        } catch (Exception e) {
            log.error("update Exception",e);
        }
        return 0;
    }



    @Override
    public int remove(Long channelId) {
//        return this.baseMapper.deleteById(appId);
        TbChannelConfig TbChannelConfig = new TbChannelConfig();
        TbChannelConfig.setChannelId(channelId);
        TbChannelConfig.setDataStatus(0);
        return this.baseMapper.updateById(TbChannelConfig);
    }

    @Override
    public TbChannelConfig getDtl(Long channelId) {
        TbChannelConfig tbChannelConfig = new TbChannelConfig();
        tbChannelConfig.setChannelId(channelId);
        tbChannelConfig.setDataStatus(1);
        return this.baseMapper.selectOne(tbChannelConfig);
    }

    @Override
    public boolean channelNameCodeExit(Map<String, Object> params) {
        boolean exit;
        exit = this.baseMapper.selectByChannelInfo(params).size() > 0;
        return exit;
    }
    
}
